define (require, exports, module) ->
	exports.mc = require('mustache')
	exports.JSON = require("json")
	exports.jsonHelp = require("./front_net/module-zic/jsonhelp")
	_ = exports._ = require("underscore")
	$ = exports.jq = require('jquery')
	$.ajaxSetup
		type: "POST"
		dataType: "json" #返回值类型
		contentType: "application/x-www-form-urlencoded; charset=utf-8" #请求参数类型
	require('./front_net/module-zic/prototype').Arrayhelp()

	require('./front_net/module/artDialog5/amd/artDialog5')($)
	require('./front_net/module-zic/area/area2')($, _, exports.mc)
	require('./front_net/module/mousewheel')($)
	require('./front_net/module/fancybox/fancybox')($)
	require('./front_net/module/fancybox/fancybox-thumbs')($)
	require('./front_net/module-zic/placeholder')($)
	require('./front_net/module-zic/bracket')($)
	require('./front_net/module/cookie')($)
	require('./front_net/module/chosen')($)
	require('./front_net/module/validation')($, _)

	require('./front_net/bootstrap/amd/bootstrap-dropdown')($)
	require('./front_net/bootstrap/amd/bootstrap-button')($)
	require('./front_net/bootstrap/amd/bootstrap-typeahead-zic')($)
	require('./front_net/bootstrap/amd/bootstrap-datepicker')($)
	require('./front_net/bootstrap/amd/bootstrap-alert')($)

	# Models
	exports.mod_itemAct = require('./scripts/itemAct')

	exports.ld_logo = ->
		logos = $("a.brand-light, a.brand-dark")
		logos.hover ->
			logos.addClass("hover", 1000)
		, ->
			logos.removeClass("hover", 1000)

	exports.dialog_config = 
		fixed: true
		lock: true
		opacity: 0.1

	exports.check_result = (e, request) ->
		if e.error
			if e.error == "need_login"
				exports.dialogin(request);
			else
				$("#main-error").show().children("strong").text(e.error)
			return false
		if e.warn
			$("#main-alert").show().children("strong").text(e.warn)
		return true

	exports.dialogin = (prerequest) ->
		dialogin_box = $("#dialogin");
		dialogin = $.dialog exports._.extend
			content: dialogin_box[0]
			initialize: ->
				$("a.submit", dialogin_box).on "click", ->
					$.ajax
						url:"/login"
						data: dialogin_box.formtoobj()
						success: (e)->
							if e.error
								$("#dialogin-error").show().children("strong").text(e.error)
								return;
							dialogin.close();
							$.ajax
								url: prerequest.url
								data: prerequest.data
								success: (e)->
									if !exports.check_result(e) then return
									window.location.reload()
		, exports.dialog_config

	# Fix
	exports.fix_tagmanage = (box) ->
		$(".tagManager", box).each ->
			source = $(this).attr("autocomplate_data").split(",")
			$(this).tagsManager
				preventSubmitOnEnter: true
				typeahead: true
				typeaheadAjaxSource: null
				typeaheadSource: source
				blinkBGColor_1: '#FFFF9C'
				blinkBGColor_2: '#CDE69C'
				hiddenInputName: "albums"

	exports.fix_placeholder = (box) ->
		$("input[placeholder], textarea[placeholder]", box).placeholder()

	exports.fix_selall = (box) ->
		$("input.selall", box).click ->
			$(this).select()

	exports.fix_bsico = (box) ->
		$("a[class*='ico[']", box).each ->
			o = $(this)
			if o.children("i").length != 0 then return
			o.bracket space: 'ico'
			o.prepend("<i class='" + o.data('ico')[0] + "'></i>")
			o.attr("class", o.attr("class").replace(/ico\[[\w-\s]+\]/g, ""))

	exports.fix_holdinput = (box) ->
		$('input.holdinput', box).holdinput()

	exports.fix_txttime = (box) ->
		$('input.txttime').datepicker()

	exports.fix_pressbar = (box) ->
		$(".pressbar", box).each ->
			o = $(this)
			val = parseInt(o.attr("title"))
			if o.attr("multi")
				val = val * o.attr("multi")
			o.progressbar 
				value: parseInt(val)
    
	exports.fix_uitips = (box) ->
		$(".uitips", box).tooltip 
			position: 
				my: "center bottom"
				at: "center top"
				offset: "0 -5"

	exports.fix_png = (box) ->
		if window.bow == "ie6"
			module.load './front_net/amd-jq/jq_pngFix', ->
				$(".png", box).pngFix()

	exports.fix_countable = (box) ->
		$(".countable", box).each ->
			$(this).countable
				threshold: 0
				target: $(this).parent().find(".cttarget")
				appendMethod: "appendTo"
				positiveCopy: "还可输入{n}个字符"

	exports.fix_facnybox = (box) ->
		$(".fancybox", box).fancybox
			prevEffect  : 'none'
			nextEffect  : 'none'
		$(".fancybox-thumb", box).fancybox
			prevEffect  : 'none'
			nextEffect  : 'none'
			helpers : 
				thumbs  : 
					width   : 100
					height  : 60

	return